<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
const list = [
		{
			"permissionid": 4,
			"name": "class",
			"path": "/class",
			"type": "1",
			"title": "班级管理"
		},
		{
			"permissionid": 4,
			"name": "classlist ",
			"path": "/classlist",
			"type": "2",
			"title": "班级列表"
		},
		{
			"permissionid": 4,
			"name": "classinfo",
			"path": "/classinfo",
			"type": "2",
			"title": "班级信息"
		},
		{
			"permissionid": 8,
			"name": "stuperson",
			"path": "/stuperosn",
			"type": "1",
			"title": "个人中心"
		},
		{
			"permissionid": 8,
			"name": "stupersoninfo",
			"path": "/studentinfo",
			"type": "2",
			"title": "个人信息"
		},
		{
			"permissionid": 8,
			"name": "stucorse",
			"path": "/stucourse",
			"type": "2",
			"title": "我的学科"
		}
	]
   
 function chanrole(data) {
    const parentMap = new Map();
    const result = [];
    // 首先遍历所有元素，创建父节点并存入Map
    for (const item of data) {
        if (item.type === '1') {
            const parent = { ...item, children: [] };
            parentMap.set(item.permissionid, parent);
            result.push(parent);
        }
    }
    // 再次遍历，将子节点添加到对应的父节点
    for (const item of data) {
        if (item.type === '2') {
            const parent = parentMap.get(item.permissionid);
            if (parent) {
                parent.children.push(item);
            }
        }
    }
    return result;
}
const aaa = chanrole(list)
const 
    const getrouter = (list) => {
    list.forEach(item => {
      const rou = {
        name: item.name,
        path: item.path,
        component: `${item.name}${item.path}`,
        children: []
      }
      console.log('rou', rou);

      if (item.children && item.children.length) {
        item.children.forEach(sitem => {
          const rou2 = {
            name: sitem.name,
            path: sitem.path,
            component: `${item.name}${sitem.path}`
          }
          if (!sitem.children) {
            console.log('rou.component', rou2.component);

            let path = loadpath(rou2.component)
            console.log('path', path);
            rou2.component = path
          }
        })
        rou.children.push(item.children)
      }
        console.log('rou.component', rou.component);
        let path = loadpath(rou.component)
        console.log('path', path);
        rou.component = path
    })
    function loadpath(url) {
      console.log('url', url);

      let Moudle = import.meta.glob("@/views/**/*.vue")
      console.log(Moudle[`/src/views/${url}.vue`]);
      console.log(Moudle);

      return Moudle[`/src/views/${url}.vue`]
    }
  }
    </script>
</body>

</html>